package List;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 强仔
 * Date: 2021-08-20
 * Time: 9:41
 */
public class TestDemo {
    public static void main1(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(5);
        list.add(6);
        list.add(7);
        list.add(1,8);

        ArrayList<Integer> list2 = new ArrayList<>();
        list2.add(100);
        list2.add(200);
        list2.add(300);
        list2.add(400);
        list.addAll(list2);
        System.out.println(list);

        System.out.println("=============================");
        //迭代器
        Iterator<Integer> iterator = list.iterator();
        while(iterator.hasNext()){                                  //判断是否有下一个
            System.out.println(iterator.next());                    //不光是打印，而且iterator向下走
        }

        System.out.println("==============================");
        for (Integer x :list) {
            System.out.println(x);
        }
    }

    public static void main2(String[] args) {
        List<Integer> list=new ArrayList<>();
        list.add(100);
        list.add(200);
        list.add(300);
        System.out.println(list);

//        int x = list.remove(1);  拆箱了
//        System.out.println(x);

        boolean y = list.remove(list.get(2));
        System.out.println(y);
        System.out.println(list);
    }
    public static void main3(String[] args) {
        List<Integer> list=new ArrayList<>();
        list.add(100);
        list.add(200);
        list.add(300);
        System.out.println(list);

        int x = list.get(1);
        System.out.println(x);

        int a=list.set(2,600);
        System.out.println(a);
        System.out.println(list);

        list.clear();
        System.out.println(list);
    }
    public static void main(String[] args) {
        List<Integer> list=new ArrayList<>();
        list.add(100);
        list.add(200);
        list.add(300);
        System.out.println(list);

//        boolean a = list.contains(100);
//        System.out.println(a);
//
//        int b = list.indexOf(200);
//        System.out.println(b);

        List<Integer> elist=list.subList(0,2);
        //前闭后开
        System.out.println(elist);
        //subList并不是截取出来一个新的数组，而是原来的数组
        elist.set(1,800);
        System.out.println(list);
    }

    public static void main5(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        ArrayList<Integer> arrayList1 = new ArrayList<>(20);
        ArrayList<Integer> arrayList2 = new ArrayList<>(arrayList);

    }
}
